package com.acpt.handler;

import com.acpt.common.CacheConstants;
import com.acpt.util.ResponseUtils;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
  @Override
  public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
    // 获取错误信息
    String exception = (String) request.getAttribute(CacheConstants.TOKEN_EXCEPTION);
    // 获取错误状态码
    String exceptionCode = request.getAttribute(CacheConstants.TOKEN_EXCEPTION_CODE).toString();
    ResponseUtils.buildResponse(response, exception, exceptionCode);
  }


}
